package com.thesis.teacher.controller;

import com.alibaba.fastjson.JSONObject;
import com.thesis.manage.common.utils.Result;
import com.thesis.manage.domain.Teacher;
import com.thesis.manage.service.TeacherService;
import com.thesis.manage.service.model.RoleEnum;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author php
 * @date 2018/2/11
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController extends BaseController {
    @Resource
    private TeacherService teacherService;

    @GetMapping("/list")
    public Map<String, Object> list(Pageable pageable) {
        return buildMessage(() -> {
            Result result = getUser();
            Teacher teacher = JSONObject.parseObject(result.getData().toString(), Teacher.class);
            String collegeName = teacher.getCollegeName();
            return teacherService.listByCollegeName(collegeName, pageable);
        });
    }

    @PostMapping("/auth")
    public Map<String, Object> authorization(Long id, Integer isAuth) {
        return buildMessage(() -> {
            teacherService.authorization(id, isAuth, RoleEnum.GUIDETEACHER.getValue().longValue());
            return null;
        });
    }
}
